<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="../../js/mui.js"></script>
		<link href="../../css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/header.css" />

		<style>

			#mui-content {
				width: 100%;
				position: absolute;
				top: 44px;
				bottom: 0px;
				background: #2e3132;
			}
			
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title" style="position: fixed;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left title-color"></a>
			<a id="linx_download_qrcode" class="mui-pull-right" style="font-size: 15px;color: white;line-height: 44px; margin-top: 2px;">
				<img src="../../image/download.png" width="20px" />
			</a>
			<span class="mui-title title-color" id="chatting-nickname" style="text-align: left; margin-top: 2px;">二维码名片</span>
		</header>

		<div id="mui-content" style="padding: 80px 30px 0px 30px;">
			<div style="background-color: white;padding-top: 20px;padding-left: 20px;">
				<img id="head_portrait" src="../../image/loading.jpg" width="60px" style="border-radius: 8%;float: left;" />
				<label id="lab_nickname" style="float: left;margin-left: 10px;margin-top: 10px;">一步青云半步雨</label>
			</div>
			<div style="background-color: white;text-align: center;">
				<img id="img_qr_code" src="../../image/loading.jpg" style="width: 100%;" />
			</div>
			<div style="background-color: white;text-align: center;">
				<p style="padding-bottom: 10px;font-size: 12px;">扫一扫上面的二维码图案，加我微信</p>
			</div>
		</div>

		<script type="application/javascript" src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init();

			mui.plusReady(function() {

				let user = app.getCacheUser();
				let qrCode = user.qrCode;
				let thumHeadPortrait = user.thumHeadPortrait;
				let nickname = user.nickname;

				// 获取屏幕宽度，设置图片
				let img_qr_code = document.getElementById("img_qr_code");
				console.log(qrCode)
				if (qrCode) {
					img_qr_code.src = qrCode;
				}

				let head_portrait = document.getElementById("head_portrait");
				if (thumHeadPortrait) {
					head_portrait.src = thumHeadPortrait;
				}

				let lab_nickname = document.getElementById("lab_nickname");
				lab_nickname.innerHTML = nickname;

				// 获取手机端可见屏幕宽度
				let imgWidth = document.body.clientWidth - 60;
				img_qr_code.width = imgWidth;
				img_qr_code.height = imgWidth;

				// 保存二维码
				let linx_download_qrcode = document.getElementById("linx_download_qrcode");
				linx_download_qrcode.addEventListener("tap", function() {
					plus.nativeUI.showWaiting("下载中...");
					let dtask = plus.downloader.createDownload(
						app.imgServerUrl + qrCode, {},
						function(d, status) {
							// 下载完成
							if (status == 200) {
								plus.nativeUI.closeWaiting();
								console.log("Download success: " + d.filename);
								plus.gallery.save(d.filename, function() {
									app.showToast("保存图片到相册成功", "success");
								});
							} else {
								plus.nativeUI.closeWaiting();
								console.log("Download failed: " + status);
							}
						});
					dtask.start();
				});
			})
		</script>
	</body>

</html>
